<template>
  <div>
    <el-table
      :data="menuList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
        <el-table-column prop="title" label="名称" sortable width="180"></el-table-column>

        <el-table-column label="图标" sortable width="180">
            <!-- 通过作用域插槽发送过来获取原来的数据 需要展示孩子的数据icon突图标 -->
            <template slot-scope="scope">
                <i :class="scope.row.icon"></i>
            </template>
        </el-table-column>

        <el-table-column label="类型" sortable width="180">
            <template slot-scope="scope">
                <el-button :type="scope.row.type==1?'primary':'success'" size="mini" >{{scope.row.type==1?'目录':'菜单'}}</el-button>
            </template>  
        </el-table-column>

        <el-table-column prop="url" label="地址"> </el-table-column>

        <el-table-column label="操作">
        <!-- 作用域插槽 将每一行循环的item数据通过scope返回给使用者 -->
        <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
            >
            <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
            >
        </template>
        </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  props: ['menuList'],

  data() {
    return {
      tableData: [
        {
          id: 3,
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
          children: [
            {
              id: 31,
              date: "2016-05-01",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1519 弄",
            },
            {
              id: 32,
              date: "2016-05-01",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1519 弄",
            },
          ],
        },
      ],
    };
  },
  methods: {
    //1.编辑菜单数据  兄弟组件传值 通过子传父 父亲再赋给表单
    handleEdit(index,row){
        //this.$emit ('父亲传递的自定义事件名字','传递的数据')
        this.$emit('edit',{index,row})
    },
    //2.删除菜单数据
    handleDelete(index,row){
        this.$emit('remove',{index,row})
    },
  },
};
</script>

<style scoped>
</style>
